package com.heima.kafka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/send")
    public String sendMessage() {
        // 发送消息到kafka
        // 需要使用KafkaTemplate
        String topic = "spring_test_156";
        kafkaTemplate.send(topic,"hello spring boot kafka!");
        return "发送成功.";
    }
}
